#include "debug.h"
#include "mav.h"
#include "record.h"
#include "mav_sink.h"

RSC_SINK_HANDLE mav_init_sink(const char *sink_name,int sink_type,struct rsc_sink_cfg *sink_cfg)
{
	if(sink_name==NULL)
	{
		SLOG(ERR,"sink_name is null!\n");
		return NULL;
	}
	if(sink_cfg==NULL)
	{
		SLOG(ERR,"sink_cfg is null!\n");
		return NULL;
	}
	MAV_HANDLE sink_handle = NULL;
	int strtype = MAV_STREAM_VAMIX;

	if(sink_type == REC_SINK_VAMIX)
		strtype = MAV_STREAM_VAMIX;
	else if(sink_type == REC_SINK_VIDEO)
		strtype = MAV_STREAM_VIDEO;
	else if(sink_type == REC_SINK_AUDIO)
		strtype = MAV_STREAM_AUDIO;

	sink_handle = mav_init_handle(sink_name,strtype);
	return sink_handle;
}

int mav_fill_sink(RSC_SINK_HANDLE sink_handle,int subtype,struct record_frame_info *frame)
{
	if(sink_handle == NULL)
	{
		SLOG(ERR,"sink_handle is null!\n");
		return -1;
	}
	if(frame == NULL)
	{
		SLOG(ERR,"frame is null!\n");
	}
	int ret = 0;
	int type = 0;

	if(subtype == REC_DTYPE_VIDEO)
		type = MAV_STREAM_VIDEO;
	else if(subtype == REC_DTYPE_AUDIO)
		type = MAV_STREAM_AUDIO;
	else if(subtype == REC_DTYPE_META)
		type = MAV_STREAM_META;

	ret = mav_write_packet((MAV_HANDLE)sink_handle,type,frame->addr,frame->len);

	return ret;
}

int mav_exit_sink(RSC_SINK_HANDLE sink_handle)
{
	mav_exit_handle((MAV_HANDLE)sink_handle); 
	return 0;
}

